import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:yysk_app/net/api/pay_url.dart';
import 'package:yysk_app/net/http.dart';
import 'package:yysk_app/pages/nft_pages/wallet_pages/bill_detail/bill_detail_page.dart';
import 'package:yysk_app/pages/nft_pages/wallet_pages/enterprise_auth/enterprise_auth_page.dart';
import 'package:yysk_app/pages/nft_pages/wallet_pages/manage_bank/manage_bank_type_page.dart';
import 'package:yysk_app/pages/nft_pages/wallet_pages/settle_detail/settle_detail_page.dart';
import 'package:yysk_app/pages/nft_pages/wallet_pages/withdraw/withdraw_page.dart';

class WalletEnterpriseController extends GetxController {
  var balance = 0.obs;
  var menuList = ['结算明细', '账单明细', '银行卡管理', '开户信息'];
  final ScrollController scrollController = ScrollController();
 final detail = '0.00'.obs;
final type = '2'.obs;
String channel = '';
@override
  void onInit() {
    super.onInit();
    channel =  (Get.arguments['channel'] ?? '') == 'DEBIT_CARD' ? 'HUIFU' : 'DIN_PAY';
    getInfo();
    type.value = Get.parameters['type'] ?? Get.arguments['type'];
    // 初始化逻辑
    scrollController.addListener(() {
      if (scrollController.position.pixels ==
          scrollController.position.maxScrollExtent) {
        getPlatformList(loadMore: true);
      }
    });
  }

  Future<void> handleRefresh() async {
    await  getInfo();
    return;
  }

  getPlatformList({loadMore = false}) {
    try {
      http.netFetch<dynamic>(
        '',
        method: Method.post,
        params: {'type': 1},
        success: (result) {
          List<dynamic> items = result.data?.list ?? [];

          // platformList.addAll(items);
        },
      );
    } catch (e) {
      debugPrint(e.toString());
    }
  }

  @override
  void dispose() {
    super.dispose();
    scrollController.dispose();
  }

  void withdraw() {
    // 提现逻辑
    // Get.snackbar('提现', '提现功能暂未开放');
    Get.toNamed('${WithdrawPage.path}?type=${type.value}&channel=${channel}');
  }

  void onSettlementDetail() {
    // Get.snackbar('结算明细', '结算明细功能暂未开放');
    // Get.toNamed(SettleDetailPage.path);
       Get.toNamed('${SettleDetailPage.path}?type=${type.value}&channel=${channel}');
  }

  void onBillDetail() {
    // Get.snackbar('账单明细', '账单明细功能暂未开放');
    // Get.toNamed(BillDetailPage.path);
       Get.toNamed('${BillDetailPage.path}?type=${type.value}&channel=${channel}');
  }

  void onBankCardManage() {
    // Get.toNamed(ManageBankTypePage.path);
       Get.toNamed('${ManageBankTypePage.path}?type=${type.value}&channel=${channel}');
    // Get.snackbar('银行卡管理', '银行卡管理功能暂未开放');
  }

  void openAccountInfo() {
    // Get.snackbar('提示', '开户信息页面待实现');
    // Get.back();
        Get.toNamed(EnterpriseAuthPage.path,arguments: {'isAuthed':true,'type':type.value,'title':'开户信息'});
  }
  Future getInfo() async {
    
    await http.netFetch<dynamic>(
      PayUrl.getWalletBalance,
      method: Method.post,
      params: {
        'channel': channel,
      },
      success: (res) {
       if(res.code==200){
        detail.value = res.data['enterpriseBalance'];
       }
      },
    );
  }
}
